#ifndef OPENCVHELPER_H
#define OPENCVHELPER_H

#include <QImage>
#include <QMetaEnum>
#include <debugx>

//#include "opencv2/core.hpp"
//#include "opencv2/imgproc.hpp"
//#include "opencv2/highgui.hpp"
#include <opencv2/opencv.hpp>

#define ArgSeparate ","
Q_DECL_EXPORT void splitArg(const std::string& str, std::vector<std::string>& result);
Q_DECL_EXPORT void splitString(const std::string& str, const std::string& splits, std::vector<std::string>& result);
typedef void (*processFun_t)(cv::Mat &input,cv::Mat &output,cv::Mat &src,std::string ext);
struct ProcessFun
{
    ProcessFun(QString name,
                     QString description,
                     processFun_t fun,
               std::string defaultArg)
    {
        this->name=name;
        this->description=description;
        this->fun=fun;
        this->defaultArg=defaultArg;
    }
    QString name;
    QString description;
    processFun_t fun;
    std::string defaultArg;//缺省参数
    std::string arg;//当前参数
};

//缺省：白底黄字  origin字体底部坐标
Q_DECL_EXPORT void cvPutTextBg(cv::Mat &img, const std::string& text, cv::Point origin=cv::Point(20,80), cv::Scalar bgColor=cv::Scalar::all(255),
                               cv::Scalar fontColor=cv::Scalar(0, 255, 255),
                               double font_scale = 2,int font_face = cv::FONT_HERSHEY_COMPLEX,
                                int thickness = 2, int lineType = cv::LINE_8,
                               bool bottomLeftOrigin = false);
//缺省：黄字  origin字体底部坐标
Q_DECL_EXPORT void cvPutText(cv::Mat &img, const std::string& text, cv::Point origin=cv::Point(20,80), cv::Scalar fontColor=cv::Scalar(0, 255, 255),
                             double font_scale = 2,int font_face = cv::FONT_HERSHEY_COMPLEX,
                              int thickness = 2, int lineType = cv::LINE_8,
                             bool bottomLeftOrigin = false);

#define QImageFormatStr(img) (QMetaEnum::fromType<QImage::Format>().key(img.format()))

Q_DECL_EXPORT QImage cvMat2QImage(const cv::Mat& mat);
Q_DECL_EXPORT cv::Mat QImage2cvMat(QImage& image);

Q_DECL_EXPORT cv::Mat QImageToMat(const QImage &image, bool cloneImageData = true);
Q_DECL_EXPORT QImage MatToQImage(const cv::Mat &mat);
Q_DECL_EXPORT QImage cvRead(QString filePath);
Q_DECL_EXPORT cv::Mat readImage(QString filePath,bool isZip=false, int flags = cv::IMREAD_COLOR);
enum FileType{
    Image,
    Video,
    Other
};
Q_DECL_EXPORT  FileType getFileType(QString filePath);
Q_DECL_EXPORT bool isImage(QString filePath);
Q_DECL_EXPORT bool isVideo(QString filePath);

//在Matlab中做图像处理可以很方便地在一个窗口中同时显示好几张图片, 但可惜的是OpenCV中并未提供此功能
//把多张图片合成一张，方便显示在一起
Q_DECL_EXPORT  void multipleImage(std::vector<cv::Mat> imgVector, cv::Mat& dst, int imgCols=2,int MAX_PIXEL=400);

Q_DECL_EXPORT  cv::Rect roiFormat(cv::Mat &input,cv::Rect rect);
Q_DECL_EXPORT  std::string type2str(int type);
Q_DECL_EXPORT  bool isCV8U(int type);

//QImage IplImageToQImage(const IplImage *iplImg);


Q_DECL_EXPORT QImage cvDft(const QImage &image);

Q_DECL_EXPORT cv::Mat dft2(cv::Mat input);//   傅里叶变换，输出mergeArray 多通道数组（实部和虚部）
Q_DECL_EXPORT cv::Mat phase(cv::Mat mergeArray); //相位谱
Q_DECL_EXPORT cv::Mat magnitude(cv::Mat mergeArray);// 幅度谱

//---
Q_DECL_EXPORT void ifft2(const cv::Mat &src, cv::Mat &Fourier);
Q_DECL_EXPORT void fft2(const cv::Mat &src, cv::Mat &Fourier);

Q_DECL_EXPORT void createHistogram(const cv::Mat  &input ,cv::Mat  &output );


#endif // OPENCVHELPER_H
